package com.px.device.controller;

import com.px.common.annotation.Log;
import com.px.common.core.controller.BaseController;
import com.px.common.core.domain.AjaxResult;
import com.px.common.core.page.TableDataInfo;
import com.px.common.enums.BusinessType;
import com.px.common.utils.poi.ExcelUtil;
import com.px.device.domain.BatteryInfo;
import com.px.device.service.IBatteryInfoService;
import com.px.framework.aes.AesSecurityParameter;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 电池管理Controller
 * 
 * @author WRJ
 * @date 2024-08
 */
@Api("电池管理")
@RestController
@RequestMapping("/device/battery")
public class BatteryInfoController extends BaseController
{
    @Autowired
    private IBatteryInfoService batteryInfoService;

    /**
     * 查询电池管理列表
     */
    @ApiOperation("查询电池管理列表")
    @PreAuthorize("@ss.hasPermi('device:DroneInfo:query')")
    @GetMapping("/list")
    @AesSecurityParameter(outEncode = true)
    public TableDataInfo list(BatteryInfo batteryInfo)
    {
        startPage();
        List<BatteryInfo> list = batteryInfoService.selectBatteryInfoList(batteryInfo);
        return getDataTable(list);
    }

    /**
     * 导出电池管理列表
     */
    @ApiOperation("导出电池管理列表")
    @PreAuthorize("@ss.hasPermi('device:DroneInfo:query')")
    @Log(title = "电池管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @AesSecurityParameter
    public void export(HttpServletResponse response, BatteryInfo batteryInfo)
    {
        List<BatteryInfo> list = batteryInfoService.selectBatteryInfoList(batteryInfo);
        ExcelUtil<BatteryInfo> util = new ExcelUtil<BatteryInfo>(BatteryInfo.class);
        util.exportExcel(response, list, "电池管理数据");
    }

    /**
     * 获取电池管理详细信息
     */
    @ApiOperation("获取电池管理详细信息")
    @PreAuthorize("@ss.hasPermi('device:DroneInfo:query')")
    @GetMapping(value = "/{id}")
    @AesSecurityParameter(outEncode = true)
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(batteryInfoService.selectBatteryInfoById(id));
    }

    /**
     * 新增电池管理
     */
    @ApiOperation("新增电池管理")
    @PreAuthorize("@ss.hasPermi('device:DroneInfo:edit')")
    @Log(title = "电池管理", businessType = BusinessType.INSERT)
    @PostMapping
    @AesSecurityParameter(outEncode = true)
    public AjaxResult add(@RequestBody BatteryInfo batteryInfo)
    {
        return toAjax(batteryInfoService.insertBatteryInfo(batteryInfo));
    }

    /**
     * 修改电池管理
     */
    @ApiOperation("修改电池管理")
    @PreAuthorize("@ss.hasPermi('device:DroneInfo:edit')")
    @Log(title = "电池管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @AesSecurityParameter(outEncode = true)
    public AjaxResult edit(@RequestBody BatteryInfo batteryInfo)
    {
        return toAjax(batteryInfoService.updateBatteryInfo(batteryInfo));
    }

    /**
     * 删除电池管理
     */
    @ApiOperation("删除电池管理")
    @PreAuthorize("@ss.hasPermi('device:DroneInfo:remove')")
    @Log(title = "电池管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @AesSecurityParameter(outEncode = true)
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(batteryInfoService.deleteBatteryInfoByIds(ids));
    }
}
